<template>
  <div class="indexBox">
    <div id="index" ref="appRef">
      <dv-loading v-if="loading">Loading...</dv-loading>
      <div v-else class="host-body">
        <div class="d-flex jc-center title-box">
          <dv-decoration-10 class="dv-dec-10" />
          <div class="d-flex jc-center">
            <dv-decoration-8 class="dv-dec-8" :color="decorationColors" />
            <div class="title">
              <span class="title-text">{{ title }}</span>
              <dv-decoration-6
                class="dv-dec-6"
                :reverse="true"
                style="width: 300px"
                :color="['#50e3c2', '#67a1e5']"
              />
            </div>
            <dv-decoration-8
              class="dv-dec-8"
              :reverse="true"
              :color="decorationColors"
            />
          </div>
          <dv-decoration-10 class="dv-dec-10-s" />
          <div class="title-time">
            {{ timeInfo.dateYear }} {{ timeInfo.dateWeek }}
            {{ timeInfo.dateDay }}
            <el-button type="info" @click="goOut" style="margin-left: 10px" :icon="Close" circle />
          </div>
          <div class="title-select">
            <dv-border-box-12 class="select-box">
              <el-select
                v-model="selValue"
                class="m-2"
                placeholder=""
                style="width: 160px"
                size="small"
              >
                <el-option
                  v-for="item in options"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </dv-border-box-12>
          </div>
        </div>

        <!-- 第二行 -->
        <!-- <div class="d-flex jc-between px-2">
            <div class="d-flex aside-width">
              <div class="react-left ml-4 react-l-s">
                <span class="react-before"></span>
                <span class="text">{{ subtitle[0] }}</span>
              </div>
              <div class="react-left ml-3">
                <span class="text">{{ subtitle[1] }}</span>
              </div>
            </div>
            <div class="d-flex aside-width">
              <div class="react-right bg-color-blue mr-3">
                <span class="text fw-b">{{ subtitle[2] }}</span>
              </div>
              <div class="react-right mr-4 react-l-s">
                <span class="react-after"></span>
                <span class="text">
                  {{ timeInfo.dateYear }} {{ timeInfo.dateWeek }}
                  {{ timeInfo.dateDay }}
                </span>
              </div>
            </div>
          </div> -->

        <div class="body-box">
          <!-- 第三行数据 -->
          <div class="content-box">
            <div>
              <dv-border-box-12>
                <leftTop :selectId="selValue" />
              </dv-border-box-12>
              <dv-border-box-12>
                <leftBottom :selectId="selValue" />
              </dv-border-box-12>
            </div>
            <div>
              <dv-border-box-12>
                <centerTop :selectId="selValue" />
              </dv-border-box-12>
              <dv-border-box-12>
                <centerBottom :selectId="selValue" />
              </dv-border-box-12>
            </div>
            <div>
              <div>
                <dv-border-box-12>
                  <rightTop :selectId="selValue" />
                </dv-border-box-12>
              </div>
              <div>
                <dv-border-box-12>
                  <rightBottom :selectId="selValue" />
                </dv-border-box-12>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script name="dataView" setup>
import {
  defineComponent,
  ref,
  reactive,
  onMounted,
  onUnmounted,
  nextTick,
} from "vue";

import { getMajor } from "@/api/dataView";
import { formatTime } from "@/utils/index";
import { WEEK } from "@/constant/index";
import useDraw from "@/utils/useDraw";
import { title, subtitle, moduleInfo } from "@/constant/index";
import leftTop from "./components/leftTop.vue";
import leftBottom from "./components/leftBottom.vue";
import centerTop from "./components/centerTop.vue";
import centerBottom from "./components/centerBottom.vue";
import rightTop from "./components/rightTop.vue";
import rightBottom from "./components/rightBottom.vue";
import { Close } from "@element-plus/icons-vue"
import { useRouter } from "vue-router"


const router = useRouter()
// 所有数据
const tenData = ref({
  list1: [],
  list2: [],
});
const dataView = ref();
// * 颜色
const decorationColors = ["#568aea", "#000000"];
// * 加载标识
const loading = ref(true);
// * 时间内容
const timeInfo = reactive({
  setInterval: 0,
  dateDay: "",
  dateYear: "",
  dateWeek: "",
});
const selValue = ref();
const options = ref([]);
// * 适配处理
const { appRef, calcRate, windowDraw, unWindowDraw } = useDraw();

// appRef.value = dataView.value

// 获取专业列表
async function getMajorList() {
  const res = await getMajor();
  options.value = res.data;
  console.log("res", res);
  selValue.value = options.value[0].id;
}

function goOut() {
  router.push('/message')
}
// 生命周期
onMounted(() => {
  cancelLoading();
  handleTime();
  nextTick(() => {
    getMajorList();
  });
  // todo 屏幕适应
  windowDraw();
  calcRate();
});

onUnmounted(() => {
  // unWindowDraw();
  clearInterval(timeInfo.setInterval);
});

// methods
// todo 处理 loading 展示
const cancelLoading = () => {
  setTimeout(() => {
    loading.value = false;
  }, 500);
};

// todo 处理时间监听
const handleTime = () => {
  timeInfo.setInterval = setInterval(() => {
    const date = new Date();
    timeInfo.dateDay = formatTime(date, "HH: mm: ss");
    timeInfo.dateYear = formatTime(date, "yyyy-MM-dd");
    timeInfo.dateWeek = WEEK[date.getDay()];
  }, 1000);
};
</script>

<style lang="scss" scoped>
@import "@/assets/scss/index.scss";

.content-box {
  display: grid;
  grid-template-columns: 2fr 3fr 5fr 3fr 2fr;
  display: flex;
  align-items: center;
  width: 100%;
  justify-content: space-between;
  .box-item1 {
    width: 25%;
  }
  .box-item2 {
    width: 48%;
  }
  .box-item3 {
    width: 25%;
  }
}
:deep(.el-select) {
  background-color: #090d1e !important;
  border: 0px solid #409eff !important;
}
:deep(.el-tooltip__trigger) {
  background-color: #090d1e !important;
  border: 0px solid #409eff !important;
  border-radius: 0px;
  color: white;
}
:deep(.el-select__wrapper) {
  // box-shadow: 0 0 0 1px #409eff !important;
  box-shadow: none !important;
}
:deep(.el-select-dropdown) {
  background-color: #409eff !important;
}
:deep(.el-select__selected-item) {
  color: white !important;
}
.select-box {
  width: 176px !important;
  margin-top: 10px;
}
</style>
